/**
 * Copyright (c) 2012-2014, Yang Yang <cntototo@gmail.com>
 *
 * This software may be distributed under the terms of the New BSD License.
 * See README for more details.
 *
 * API to communicate with WFS daemon.
 */

#ifndef WFS_API_H
#define WFS_API_H

#ifdef __cplusplus
extern "C" {
#endif

/** UDP command port */
#define WFS_UDP_CMD_PORT 7262
/** UDP event port */
#define WFS_UDP_EVT_PORT 7263

/** Prefix of WFS events */
/** TODO: Add all events's prefix here */

/**
 * struct wfs_handle_params -- A group of parameters needed to create WFS handle
 */
struct wfs_handle_params {
	/** Interface name */
	char ifname[17];
};

/** struct wfs_msg -- Structure of message to/from WFS daemon */
struct wfs_msg {
	/** Body length, include '\0' */
	unsigned int len;
	/** Message body */
	char *body;
};

/**
 * enum wfs_error -- Error type
 *
 * WFS_ERR_SUCCESS: The operation succeeds.
 * WFS_ERR_INVAL: The input info is invalid.
 * WFS_ERR_OOM: Out of memory.
 * WFS_ERR_OS: Failure in OS, such as TCP/IP stack failure.
 */
enum wfs_error {
	WFS_ERR_SUCCESS = 0,
	WFS_ERR_INVAL,
	WFS_ERR_OOM,
	WFS_ERR_OS
};

/**
 * wfs_connect -- Connect to WFS daemon
 */
struct wfs_handle *wfs_connect(const struct wfs_handle_params *params);

/**
 * wfs_disconnect -- Disconnect to WFS daemon
 */
void wfs_disconnect(struct wfs_handle *handle);

/**
 * wfs_send -- Send command to WFS daemon
 */
enum wfs_error wfs_send(struct wfs_handle *handle, const struct wfs_msg *cmd,
		struct wfs_msg *resp);

/**
 * wfs_recv -- Receive event from WFS daemon
 */
enum wfs_error wfs_recv(struct wfs_handle *handle, struct wfs_msg *event);

/**
 * wfs_get_cmd_sock -- Get command socket of struct wfs_handle
 */
int wfs_get_cmd_sock(struct wfs_handle *handle);

/**
 * wfs_get_evt_sock -- Get event socket of struct wfs_handle
 */
int wfs_get_evt_sock(struct wfs_handle *handle);

#ifdef __cplusplus
}
#endif

#endif /* WFS_API_H */
